<?php
	session_start();
	if(!isset($_SESSION["jara_admin"])) {
		header("Location: ../login.php");
		exit;
	}
	if($_SESSION["jara_permissions"][0] == 0) {	
		header("Location: error.php");
		exit;
	}
	require_once("../include/templating_fns.php");
	require_once("../include/db_fns.php");
	jara_page_start("Comments - Administrator CP");
	$result = jara_db_query("select * from jara_comments order by time desc");
	$num_posts = $result->num_rows;
?>
	<p>&nbsp;</p>
	<table border="1" class="admin-table">
		<tr>
			<th width="220"><strong>Post and Content</strong></th>
			<th width="120"><strong>Date</strong></th>
			<th width="70"><strong>Author</strong></th>
			<th width="60"><strong>Actions</strong></th>
		</tr>
<?php
	if($num_posts == 0) {
?>
		<tr>
			<td colspan="4" align="center">There are no comments.</td>
		</tr>
<?php
	}
	for($i = 0; $i < $num_posts; $i++) {
		$row = $result->fetch_assoc();
?>
		<tr>
			<td><a href="../view.php?id=<?php echo $row["postid"]; ?>"><?php echo jara_post_title($row["postid"]); ?></a><br /><?php echo $row["comment"]; ?></td>
			<td><?php echo date("jS F Y", $row["time"]); ?></td>
			<td><?php echo $row["name"]; ?></td>
			<td>
				<a href="javascript:;" onclick="var q = confirm('Are you sure you want to delete this comment?'); if(q) { window.location.href = 'delete_comment.php?id=<?php echo $row["id"]; ?>&in_cp' }" title="Delete Comment"><img src="images/jara_delete.png" alt="Delete Comment" border="0" style="border: none" /></a>
			</td>
		</tr>
<?php
	}
?>
	</table>
<?php
	jara_page_end();
?>